#include <iostream>
#include <cstdlib>
#include <cassert>
#include <string>
#include <time.h>
using namespace std;

#include "Graph.h"
#include "Node.h"
#include "Algorithm.h"
#include "tests/AlgorithmTest.h"
#include "test.h"

static int iteration = 0;

static string trace_id() {
    int i = ++iteration;
    ostringstream buffer;
    buffer << i;
    return "graph/graph_" + buffer.str() + ".dot";
}

static string trace_id2() {
    int i = ++iteration;
    ostringstream buffer;
    buffer << i;
    return "graph/graph_____________" + buffer.str() + ".dot";
}
static string trace_id(int i) {
    ostringstream buffer;
    buffer << i;
    return buffer.str();
}
int main() {
    string tab[12] = {"graphe1", "graphe2", "graphe3", "graphe4", "graphe5", "graphe6", "graphe7", "graphe8", "graphe9", "graphe10", "graphe11", "graphe12"};

    int couleur, i;
    for (couleur = 7; couleur < 8; couleur++) {
        for (i = 0; i < 12; i++) {
                Graph * g = new Graph("echantillon_test/" + tab[i]);
                g->saveOnCnfFile(tab[i] + "_" + trace_id(couleur), couleur);
        }
    }

    
    /*double time_total;
    struct timespec t_start, t_end;

    int i, j;
    cout << "-- Greedy Algorithm --" << endl;
    for (i = 0; i < 12; i++) {
        Graph * g = new Graph("echantillon_test/" + tab[i]);

        clock_gettime(CLOCK_MONOTONIC, &t_start);
        int res = greedy_algorithm(g);
        clock_gettime(CLOCK_MONOTONIC, &t_end);
        time_total = (double) (t_end.tv_sec - t_start.tv_sec) + 1.e-9 * (t_end.tv_nsec - t_start.tv_nsec);
        cout << tab[i] << " " << res << " " << time_total << "s" << endl;

    }

    cout << endl << endl << "-- Backtrack Algorithm --" << endl;
    for (j = 2; j < 8; j++) {
        cout << endl << j << " couleurs :" << endl;
         for (i = 0; i < 12; i++) {
            Graph * g = new Graph("echantillon_test/" + tab[i]);

            clock_gettime(CLOCK_MONOTONIC, &t_start);
            int res = backtracking_algorithm(g, j);
            clock_gettime(CLOCK_MONOTONIC, &t_end);
            time_total = (double) (t_end.tv_sec - t_start.tv_sec) + 1.e-9 * (t_end.tv_nsec - t_start.tv_nsec);
            cout << tab[i] << " " << res * 100 / g->size() << "% " << time_total*1000 << " ms" << endl;
        }
    }

    cout << endl << endl << "-- Nochoice Algorithm --" << endl;
     for (j = 2; j < 8; j++){
        cout << endl << j << " couleurs :" << endl;
        for (i = 0; i < 12; i++) {
            Graph * g = new Graph("echantillon_test/" + tab[i]);

            clock_gettime(CLOCK_MONOTONIC, &t_start);
            int res = nochoice_algorithm(g, j);
            clock_gettime(CLOCK_MONOTONIC, &t_end);
            time_total = (double) (t_end.tv_sec - t_start.tv_sec) + 1.e-9 * (t_end.tv_nsec - t_start.tv_nsec);
            cout << tab[i] << " " << res * 100 / g->size() << "% " << time_total*1000 << " ms" << endl;
        }
    }

    cout << endl << endl << "-- Nochoice Optimized Algorithm --" << endl;
    for (j = 2; j < 8; j++) {
        cout << endl << j << " couleurs :" << endl;
         for (i = 0; i < 12; i++){
            Graph * g = new Graph("echantillon_test/" + tab[i]);

            clock_gettime(CLOCK_MONOTONIC, &t_start);
            int res = nochoice_algorithm_optimized2(g, j);
            clock_gettime(CLOCK_MONOTONIC, &t_end);
            time_total = (double) (t_end.tv_sec - t_start.tv_sec) + 1.e-9 * (t_end.tv_nsec - t_start.tv_nsec);
            cout << tab[i] << " " << res * 100 / g->size() << "% " << time_total*1000 << " ms" << endl;
        }
    }*/
     
    return EXIT_SUCCESS;
}
